import 'package:get/get.dart';
import 'package:xiaomi_shop/app/services/iconWrapper.dart';
import 'package:xiaomi_shop/app/services/userService.dart';
import 'package:xiaomi_shop/models/index.dart';

class UserController extends GetxController {
  List serviceIcons = [
    {"iconName": IconWrapper.daishouhuo, "title": "一键安装"},
    {"iconName": IconWrapper.biaoqian, "title": "一键退换"},
    {"iconName": IconWrapper.daifahuo, "title": "一键维修"},
    {"iconName": IconWrapper.daifukuan, "title": "服务进度"},
    {"iconName": IconWrapper.daipingjia, "title": "小米之家"},
    {"iconName": IconWrapper.dingdan, "title": "客服中心"},
    {"iconName": IconWrapper.fankui, "title": "以旧换新"},
    {"iconName": IconWrapper.qiandao, "title": "手机电池"},
  ];

  List adList = ["assets/images/user_ad1.png", "assets/images/user_ad2.png"];

  RxBool loginState = false.obs;
  Rx<UserModel?> userModel = Rx(null);

  @override
  void onInit() {
    super.onInit();
    getUserInfo();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  // 获取用户信息
  getUserInfo() async {
    loginState.value = await UserService.getUserLoginState();
    UserModel? user = await UserService.getUser();
    print("user $user");
    if (user != null) {
      userModel.value = user;
    }
  }

  loginOut() {
    UserService.loginOut();
    loginState.value = false;
    userModel.value = null;
  }
}
